package com.epam.railway.jdbc.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionManager {
	
private static Connection connection = null;
	
	public static Connection createConnection() {
		String jdbcUrl = "jdbc:mysql://127.0.0.1/railway";
		String user = "root";
		String password = "root";
	
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(jdbcUrl,user,password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return connection;
	}
	
	public static Connection getConnection() {
		if(connection==null) {
			createConnection();
		}
		return connection;
	}

}
